<div class="layuimini-container layui-anim layui-anim-upbit">
    <div class="layuimini-main" style="text-align: center;">
        <div style="margin: 10px 10px 10px 10px">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item" style="text-align: center;">
                    <div class="layui-inline">
                        <label class="layui-form-label">数据库</label>
                        <div class="layui-input-inline">
                            <select id="dbCode" style="text-align: center;text-align-last: center;width: auto;"
                                autocomplete="off" class="layui-input" lay-filter="dbCode">
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" class="layui-btn layui-btn-warm" id="template"
                            style="border-radius:6px;background-color:#26B99A;"> <i class="fa fa-cloud-download"></i>
                            模板下载</button>
                        <button type="button" class="layui-btn layui-btn-warm" id="test4"
                            style="border-radius:6px;background-color:#1e9fff;">
                            <i class="fa fa-cloud-upload"></i> 批量导入</button>
                    </div>
                </div>
            </form>
            <span style="width: 190px;margin-top: 2px;text-align: center;">
                注意：批量上传需将文件打包至如下格式，文件夹与Excel需与示例同名：<br>
                如：上传情报资源：文件夹名为JZQBZS, Excel名为JZQBZS.xlsx;</span>
            <div style="text-align: center;margin-top: 20px;">
                <img src="/admin/images/JZQBZS.jpg" id="detail" style="width: 600px;height: 600px;">
            </div>
        </div>
    </div>
</div>

<script>

    //初始化配置数据
    $(function () {
        //拼接数据库下拉框
        var nameList = config.json.db;
        var option = "";
        for (var i = 0; i < nameList.length; i++) {
            if (nameList[i].dataPermissionTree) {
                option += "<option value='" + nameList[i].dbCode + "'>" + nameList[i].showName + "</option>";//循环获取返回值，并组装成html代码
            }
        }
        $("#dbCode").html('');
        $("#dbCode").append(option);
        layui.form.render('select', 'dbCode');
    })

    //渲染页面
    layui.form.render();
    var dbCode = "";

    layui.form.on('select(dbCode)', function () {
        dbCode = $("#dbCode").val().split("_")[0];
        var detail = "/admin/images/" + dbCode + ".jpg";
        $('#detail').attr('src', detail)

    })

    function showloading(t) {
        if (t) {//如果是true则显示loading
            loading = layer.load(1, {
                shade: [0.3, '#000'], //0.1透明度的白色背景
                content: '<p style="position: relative;left: -50px;">文件批量上传中,请耐心等待...</p>',
                success: function (layerContentStyle) {
                    layerContentStyle.find('.layui-layer-content').css({
                        'padding-top': '50px',
                        'text-align': 'left',
                        'line-height': '30px',
                        'color': '#fff',
                        'width': '300px'
                    })
                }

            });
        } else {//如果是false则关闭loading
            layer.closeAll('loading');
        }
    }


    layui.upload.render({ //允许上传的文件后缀
        headers: { token: shared.getCookie('token') },
        elem: '#test4'
        , url: config.server + '/adminQBZS/batchImport'
        , before: function (obj) {
            this.data = { 'dbCode': $("#dbCode").val().split("_")[0] };
            showloading(true);
        }
        , accept: 'file' //普通文件
        , exts: 'zip' //只允许上传压缩文件
        , size: 11000000//设置文件最大可允许上传的大小10G，单位 KB。不支持ie8/9
        , done: function (res) {
            showloading(false)
            if (res.code != 200) {
                // layer.msg('上传失败! ' + res.msg);
                alert(res.msg)
            } else {

                layer.msg(res.msg);
                return;
            }
        }, error: function () {
        }

    });

    $("#template").click(function () {
        url = config.server + '/adminQBZS/getTemplate?dbCode=' + $("#dbCode").val().split("_")[0];
        window.location.href = url;
    })
</script>